package com.xxc.exam.service.impl

import com.xxc.batis.service.CrudServiceImpl
import com.xxc.exam.entity.pojo.SelectionQues
import com.xxc.exam.mapper.SelectionQuesMapper
import com.xxc.exam.service.SelectionQuesService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service
import java.lang.StringBuilder
import java.math.BigInteger

@Service
class SelectionQuesServiceImpl : SelectionQuesService, CrudServiceImpl<SelectionQues, BigInteger, SelectionQuesMapper>() {
    override fun getSelectionsPerScore(ids: List<BigInteger>): Map<BigInteger, Int> {
        if(ids.isEmpty())
            return emptyMap()
        val builder = ids.fold(StringBuilder()) { builder, item ->
            builder.append(item).append(',')
        }
        builder.deleteCharAt(builder.length - 1)
        val map = mutableMapOf<BigInteger,Int>()
        crudMapper.selectByIds(builder.toString()).forEach {
            map[it.id!!] = it.perScore!!
        }
        return map
    }
}